<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

?>

<script language="javascript">
	function saveResults( n ) {
		for ( var j = 0; j <= n; j++ ) {
			box = eval( "document.adminForm.cb" + j );
			if ( box ) {
				if ( box.checked == false ) {
					box.checked = true;
				}
				} else {
					alert("You cannot change the order of items, as an item in the list is `Checked Out`");
					return;
				}
			}
		submitform('saveresults');
	}
</script>

<form action="index2.php" method="post" name="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr>
			<td width="10%">&nbsp;</td>
			<td width="50%" nowrap="nowrap">
				<?php echo mosHTML::selectList( $this->teams, 'team1', 'class="inputbox" size="1"','value', 'text', 0); ?>
				&nbsp;:&nbsp;
				<?php echo mosHTML::selectList( $this->teams, 'team2', 'class="inputbox" size="1"','value', 'text', 0); ?>
				<input type="button" name="" class="button" value="add" onClick="javascript:submitbutton('quickadd');" />
			</td>
			<td nowrap="nowrap">
				<input type="button" name="" class="button" value="current" onClick="javascript:submitbutton('setcurrent');" />
				<?php echo mosHTML::selectList( $this->rounds, 'rid', 'class="inputbox" onChange="javascript:document.adminForm.submit();" size="1" style="width:150px;"','value', 'text', $this->defaults["rid"] );?>
			</td>
<?php	if($this->project->getParam("groups_supported", 0)){ ?>
			<td>
				<?php echo mosHTML::selectList($this->groups, 'group', 'class="inputbox" onChange="javascript:document.adminForm.submit();" size="1"', 'value', 'text', $this->defaults["group"]);?>
			</td>
<?php 	} ?>
			<td><?php echo mosHTML::selectList( $this->teams, 'tid', 'class="inputbox" onChange="javascript:document.adminForm.submit();" size="1"','value', 'text', $this->defaults["tid"] );?></td>
			<td><?php echo mosHTML::selectList( $this->modes, 'mode', 'class="inputbox" onChange="javascript:document.adminForm.submit();" size="1"','value', 'text', $this->defaults["mode"] );?></td>
		</tr>
	</table>
	
	<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
		<tr>
			<th width="1%">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->rows ); ?>);" />
			</th>
<?php 	if($this->project->getParam("groups_supported", 0)){ ?>
			<th width="10%" align="center">Group</th>
<?php	} ?>
			<th>Date/Time</th>
			<th width="20%" align="right">Home</th>
			<th width="5">&nbsp;</th>
			<th width="20%" align="left">Away</th>
			<th width="10%" align="center">EndResult</th>
			<th>
				<a href="javascript: saveResults( <?php echo count( $this->rows ) - 1; ?> )">
					<img src="images/filesave.png" border="0" width="16" height="16" alt="Save Results" />
				</a>
			</th>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 0 ){ ?>
			<th width="8%" align="center">Chapter1</th>
<?php	} ?>
<?php	if($this->project->getParam("cnt_chapters", 0) > 1 ){ ?>
			<th width="8%" align="center">Chapter2</th>
<?php	} ?>
<?php	if($this->project->getParam("cnt_chapters", 0) > 2 ){ ?>
			<th width="8%" align="center">Chapter3</th>
<?php	} ?>
<?php	if($this->project->getParam("cnt_chapters", 0) > 3 ){ ?>
			<th width="8%" align="center">Chapter4</th>
<?php	} ?>
<?php	if($this->project->getParam("cnt_chapters", 0) > 4 ){ ?>
			<th width="8%" align="center">Chapter5</th>
<?php	} ?>
			<th width="8%">Actions</th>
		</tr>
<?php
	$k = 0;
	$i = 0;
	foreach($this->rows as $row) {
		$ro = new ResultTransferObject($row);
		
		$k = 1 - $k;
		
		$task1	= $row->published ? 'unpublish' : 'publish';
		$img1	= $row->published ? 'tick.png' : 'publish_x.png';
		
		$task2	= $row->match_info_flag ? 'unsetInfo' : 'setInfo';
		$img2	= $row->match_info_flag ? 'tick.png' : 'publish_x.png';
		
		$mstl = '&nbsp;';
		if($this->project->getParam("allow_extra_time", 0)){
			$types = array();
			$types[] = mosHTML::makeOption(0, "regular");
			$types[] = mosHTML::makeOption(1, "extra");
			$types[] = mosHTML::makeOption(2, "penalty");
			
			$mstl = mosHTML::selectList( $types, "match_result_type[]", 'class="text_area" size="1"','value', 'text', $row->match_result_type );
			unset($types);
		}
?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->match_id; ?>" onclick="isChecked(this.checked);" />
			</td>
<?php	if($this->project->getParam("groups_supported", 0)){ ?>
			<td align="center">
				<?php echo mosHTML::selectList($this->groups, 'match_group[]', 'class="text_area", size="1"', 'value', 'text', $row->match_group);?>
			</td>
<?php 	} ?>
			<td align="center" nowrap="nowrap">
				<input type="text" name="match_date[]" size="10" value="<?php echo $row->match_date; ?>" class="text_area" style="text-align: center" />
				<input type="text" name="match_time[]" size="5" value="<?php echo substr($row->match_time, 0, 5); ?>" class="text_area" style="text-align: center" />
			</td>
			<td align="right"><?php echo $ro->getTeam1Name(); ?></td>
			<td align="center">-</td>
			<td align="left"><?php echo $ro->getTeam2Name(); ?></td>
			<td align="center" nowrap="nowrap" bgcolor="#EFEFEF" colspan="2">
				<input type="text" name="match_result_0_1[]" size="2" value="<?php echo $row->match_result_0_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_0_2[]" size="2" value="<?php echo $row->match_result_0_2; ?>" class="text_area" style="text-align: center" />
				<?php echo $mstl;?>
			</td>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 0 ){ ?>
			<td align="center" nowrap="nowrap">
				<input type="text" name="match_result_1_1[]" size="2" value="<?php echo $row->match_result_1_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_1_2[]" size="2" value="<?php echo $row->match_result_1_2; ?>" class="text_area" style="text-align: center" />
			</td>
<?php	} ?>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 1 ){ ?>
			<td align="center" nowrap="nowrap" bgcolor="#EFEFEF">
				<input type="text" name="match_result_2_1[]" size="2" value="<?php echo $row->match_result_2_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_2_2[]" size="2" value="<?php echo $row->match_result_2_2; ?>" class="text_area" style="text-align: center" />
			</td>
<?php	} ?>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 2 ){ ?>
			<td align="center" nowrap="nowrap">
				<input type="text" name="match_result_3_1[]" size="2" value="<?php echo $row->match_result_3_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_3_2[]" size="2" value="<?php echo $row->match_result_3_2; ?>" class="text_area" style="text-align: center" />
			</td>
<?php	} ?>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 3 ){ ?>
			<td align="center" nowrap="nowrap">
				<input type="text" name="match_result_4_1[]" size="2" value="<?php echo $row->match_result_4_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_4_2[]" size="2" value="<?php echo $row->match_result_4_2; ?>" class="text_area" style="text-align: center" />
			</td>
<?php	} ?>
<?php 	if($this->project->getParam("cnt_chapters", 0) > 4 ){ ?>
			<td align="center" nowrap="nowrap">
				<input type="text" name="match_result_5_1[]" size="2" value="<?php echo $row->match_result_5_1; ?>" class="text_area" style="text-align: center" />
				:
				<input type="text" name="match_result_5_2[]" size="2" value="<?php echo $row->match_result_5_2; ?>" class="text_area" style="text-align: center" />
			</td>
<?php	} ?>
			<td align="center" nowrap="nowrap">
				<a href="#<?php echo $task1;?>" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task1;?>')" onmouseover="this.T_WIDTH=120;return escape('<b><?php echo ucfirst($task1);?></b> this Result!')">
					<img src="images/<?php echo $img1;?>" width="12" height="12" border="0" alt="" />
				</a>
				&nbsp;
				<a href="#<?php echo $task2;?>" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task2;?>')" onmouseover="this.T_WIDTH=120;return escape('<b><?php echo ucfirst($task2);?></b> this Result!')">
					<img src="images/<?php echo $img2;?>" width="12" height="12" border="0" alt="" />
				</a>
				&nbsp;
				<a href="#events" onclick="return listItemTask('cb<?php echo $i;?>','events')" onmouseover="this.T_WIDTH=120;return escape('<b>Manage Events</b> of this Result!')">
					<img src="../includes/js/ThemeOffice/edit.png" alt="Eventmanager" border="0" />
				</a>
				&nbsp;
				<a href="#lineup" onclick="return listItemTask('cb<?php echo $i;?>','lineup')" onmouseover="this.T_WIDTH=120;return escape('<b>Manage Linup</b> of teams!')">
					<img src="../includes/js/ThemeOffice/edit.png" alt="Lineup" border="0" />
				</a>
			</td>
		</tr>
<?php
		$i++; 
	} 
?>
	</table>
	
	<input type="hidden" name="option" value="com_leagueman" />
	<input type="hidden" name="act" value="matches" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
</form>